package com.hl.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.entity.Problem;
import com.hl.sfzy.mapper.ProblemMapper;
import com.hl.sfzy.service.ProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ProblemServiceImpl
 * @Description TODO
 * @Author Jerry
 * @Date 2024年01月11日 21:14
 * @Version 1.0
 */
@Service("problemService")
public class ProblemServiceImpl implements ProblemService {
    @Autowired
    private ProblemMapper ProblemMapper;
    @Override
    public void add(Problem entity) throws Exception {
        ProblemMapper.insert(entity);
    }

    @Override
    public void edit(Problem entity) {
        ProblemMapper.update(entity);
    }

    @Override
    public void remove(Integer id) {
ProblemMapper.delete(id);
    }

    @Override
    public void removeBatch(Integer[] ids) {
ProblemMapper.deleteBatch(ids);
    }

    @Override
    public List<Problem> find(Problem entity) {
        return ProblemMapper.select(entity);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Problem entity) {
        PageHelper.startPage(pageNum, pageSize);

        List<Problem> list = ProblemMapper.select(entity); // 当前页数据

        PageInfo<Problem> pageInfo = new PageInfo<>(list); // 分页信息对象

        /*
         * 把前台需要的数据反馈
         * 1、当前页面数据（数据列表）
         * 2、此次查询的总记录数
         */
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put(CommonConstant.PAGE_LIST, list);
        pageMap.put(CommonConstant.PAGE_TOTAL, pageInfo.getTotal());

        return pageMap;
    }

    @Override
    public Problem findById(Integer id) {
        return null;
    }


    @Override
    public List<Problem> findByuserid(Integer id) {
        return ProblemMapper.selectByUserid(id);
    }

    @Override
    public Map<String, Object> findByPlo(Integer pageNum, Integer pageSize,Problem problem) {
        PageHelper.startPage(pageNum, pageSize);
        List<Problem> list = ProblemMapper.selectByPlo(problem); // 当前页数据

        PageInfo<Problem> pageInfo = new PageInfo<>(list); // 分页信息对象

        /*
         * 把前台需要的数据反馈
         * 1、当前页面数据（数据列表）
         * 2、此次查询的总记录数
         */
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put(CommonConstant.PAGE_LIST, list);
        pageMap.put(CommonConstant.PAGE_TOTAL, pageInfo.getTotal());

        return pageMap;
    }
}
